/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Service;

import DAO.DAO;
import DAO.IGroupPlanImpl;
import java.util.List;
import javabeans.Event;
import javabeans.GroupPlan;

/**
 *
 * @author liweijiao
 */
public class GroupPlanServiceImpl implements GroupPlanService {

    IGroupPlanImpl groupplanDao = new IGroupPlanImpl();
    EventServiceImpl eventSI = new EventServiceImpl();

    public GroupPlan newGroupPlan(String planname, String descrip) {
        GroupPlan gp = new GroupPlan();
        gp.setGroupplanname(planname);
        gp.setPlandescript(descrip);
        if (groupplanDao.newGroupPlan(gp) != null) {
            DAO.close();
            return gp;
        } else {
            DAO.close();
            return null;
        }


    }

    public GroupPlan getGroupPlan(int gpID) {
        GroupPlan gp = groupplanDao.getGroupPlan(gpID);
        DAO.close();
        return gp;
    }

    public Event addGroupEvent(String ename, String etype, String starttime, String endtime, String edescript, double x, double y, String c, GroupPlan groupplan) {
         Event newevent= eventSI.newGroupEvent(ename, etype, starttime, endtime, edescript, x,y, c, groupplan);
        if (newevent != null) {
            groupplan.getEvents().add(newevent);
            groupplanDao.updateGroupPlan(groupplan);
            return newevent;
        } else {
            return null;
        }
    }

    public Event modifyGroupEvent(int eid, String ename, String etype, String starttime, String endtime, String edescript, double x, double y, String c, GroupPlan groupplan) {
       return eventSI.modifyGroupEvent(eid, ename, etype, starttime, endtime, edescript, x,y, c, groupplan);
    }

    public boolean deleteGroupEvent(int eventid, int groupplanid) {
        return eventSI.deleteGroupEvent(eventid, groupplanid);
    }

    public List<Event> getGroupEventList(int groupplanid) {
         return eventSI.getGroupEventList(groupplanid);
    }

    public List<GroupPlan> viewAllGroupPlan() {
       List<GroupPlan> list=groupplanDao.viewAllGroupPlan();
       DAO.close();
       return list;
    }

    public boolean deleteGroupPlan(GroupPlan gplan) {
      return groupplanDao.deleteGroupPlan(gplan);
    }
}
